'''
Created on 31/12/2009

@author: emlyn
'''
from google.appengine.ext import db

class FileData(db.Model):
    sitename = db.StringProperty(multiline=False)
    filename = db.StringProperty(multiline=False)
    authoremail = db.StringProperty(multiline=False)
    bytes = db.BlobProperty()
    mimetype = db.StringProperty(multiline=False)
    date = db.DateTimeProperty(auto_now_add=True)

    def GetFilesForSiteName(cls, aSiteName):
        return FileData.GetFilesForSiteNameWithAmountAndOffset(aSiteName, 1000, 0)
    GetFilesForSiteName = classmethod(GetFilesForSiteName)

    def GetFilesForSiteNameWithAmountAndOffset(cls, aSiteName, amount, offset):
        Files_query = FileData.all().filter('sitename =', aSiteName)
        retval = Files_query.fetch(amount, offset)      
        return retval
    GetFilesForSiteNameWithAmountAndOffset = classmethod(GetFilesForSiteNameWithAmountAndOffset)

    def GetFileBySiteNameAndFileName(cls, aSiteName, aFileName):
        retval = None
        Files_query = FileData.all().filter('sitename =', aSiteName).filter('filename =', aFileName)
        Files = Files_query.fetch(1)      
        if Files:
            retval = Files[0]
        return retval
    GetFileBySiteNameAndFileName = classmethod(GetFileBySiteNameAndFileName)
